<?php
//DB Created by Rich L. a member in service in Northern Delaware.  Please feel free to share this code wherever it may be useful to alcholoics.  Should you have questons please contact me at sobernerd@gmail.com
require_once ('config/include_paths.php');
require_once('config.php');
require_once ('functions.php'); 
$pageTitle = SITE_NAME.' - Search Results';	
require_once ('dbconnect.php');
require_once ('head.php');
$reprowcolor = '#DDDDDD';
if ($_GET['day']) {
$daychoice="and day = '$_GET[day]'";
		  }

if ($_GET['city']) {
$citychoice="and city = '$_GET[city]'";
		  }

if ($_GET['openclose']) {
$openchoice="and open_closed = '$_GET[openclose]'";
				}

if ($_GET['men_women']) {
$menchoice="and men_women = '$_GET[men_women]'";
				}	

if ($_GET['group'])  	{
$groupchoice="and groupname = '$_GET[group]'";					  
				}
				
if ($_GET['meeting_type'])  	{
$meetingtypechoice="and meeting_types.id = '$_GET[meeting_type]'";					  
				}
/* meetings query */
			$meetings_sql = "SELECT meetings.id AS meeting_id, day, mtime, city, zip, name, group_id, groupname, code, meeting_types.id, open_closed, men_women, hc
			FROM meetings,groups,locations,meeting_types 
			WHERE group_id=groups.id and location_id=locations.id and mtg_type_id=meeting_types.id $daychoice $citychoice $openchoice 
			$menchoice $groupchoice $meetingtypechoice ORDER BY day, mtime, city ASC";
$result = mysql_query($meetings_sql) or die(mysql_error());
$num_rows = mysql_num_rows($result);
?>
<body>
<div id="wrapper">
  <?php require_once ('header.php'); ?>
    <div id="content">
        <table class="tabletext">
          <tr height="26">
            <th class="reportheader">Day/Time</th>
            <th class="reportheader">City</th>
            <th class="reportheader">Group/Location</th>
            <th class="reportheader">Type</th>
            <th class="reportheader">M/W</th>
            <th class="reportheader">HC</th>
          </tr>
          <?php		
if ($num_rows > 0)
{
	$i = 0;
	$dayheader = 0;
	// Get each row of data on each iteration until there is no more rows
	//outer loop begin
	while($row = mysql_fetch_assoc($result)){
			// Set $dayName
			$dayName = getDay($row['day']);
			// Set Time variables for reading
			$meetings_time=$row['mtime'];
			$rawtime = strtotime($meetings_time);	
			$meetings_time = date('g:iA',$rawtime);
			$city="$row[city]";
			$groupname="$row[groupname]";
			$group_id="$row[group_id]";			
			$location_name="$row[name]";
			$meeting_types_code="$row[code]";
			// set row color		
			if ($i%2 == 0) 
			{
			$rowcolor="$reprowcolor";
			} else 
			{
			$rowcolor="#EEEEEE";
			}
			// set heading if new day
			if ($dayheader != $row['day'])
			{echo "<tr><td class=\"dayheader\" colspan=\"9\"><div align=\"left\">$dayName</div></td></tr>";
			$dayheader = $row['day'];
			$rowcolor="$reprowcolor";
			$i = 0;}
			?>
          <tr onClick="DoNav('meeting_info.php?id=<?php echo $row['meeting_id'] ?>');" onMouseOver="this.bgColor='#c2e7fb';" onMouseOut="this.bgColor='<?php echo $rowcolor?>';" bgcolor="<?php echo $rowcolor?>" style="cursor:pointer">
            <td><?php echo "$meetings_time";?></td>
            <td><?php echo "$city";?></td>
            <td>
                <noscript>
                <a href="meetinginfo.php?id=<?php echo $row['id']?>">
                </noscript>
                <?php echo "$groupname";?>
                <noscript>
                </a>
                </noscript>
                <br />
              
              <div align="left"><?php echo "$location_name";?></div></td>
            <td><div align="left"><?php echo "$row[open_closed]";?>&nbsp;<?php echo "$meeting_types_code";?></div></td>
            <td><?php echo "$row[men_women]";?></td>
            <td><?php echo "$row[hc]";?></td>
          </tr>
          <?php 
		$i++;	
	// Outer loop end (group)						
	}
	echo "<tr><td><a href=\"search.php\">new search</a></tr></td>";
	echo "</table>";

    mysql_close($conn); 
          }else{
          
          ?>
          <tr bgcolor="<?php echo $rowcolor?>">
            <td colspan="9" align="right" valign="top"><div align="left" class="boldred"> No results, please broaden your search parameters." </div></td>
          </tr>
          <tr>
            <td ><a href="meeting_search.php">new search</a></td>
          </tr>
          <?php } ?>
        </table>
      </div>
    <div class="clearfloat">&nbsp;</div>
    </div>
</body>
</html>